package com.honour.controller.interfaced;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alipay.util.AliPayUtil;
import com.honour.service.interfaced.SortInManager;
import com.honour.service.interfaced.UserInManager;
import com.honour.service.interfaced.impl.AdvertisementInService;
import com.honour.service.interfaced.impl.EnergyInService;
import com.system.controller.base.BaseController;
import com.system.util.AppUtil;
import com.system.util.DateUtil;
import com.system.util.MapDistance;
import com.system.util.NetworkUtil;
import com.system.util.PageData;
import com.system.util.Tools;
import com.system.util.ToolsUtil;
import com.wxpay.util.WXPayUtil;



/**
 @Function   首页中特权美食分类
 @Author 于泓磊
 @Date   2017年10月31日
*/

@Controller
@RequestMapping(value="/appsfoodin")
public class SortInController extends BaseController{
	
	@Resource(name="sortinService")
	private SortInManager sortinService;
	
	@Resource(name="userinService")
	private UserInManager userinService;
	
	@Resource(name="energyInService")
	private EnergyInService energyInService;
	
	@Resource(name="advertisementInService")
	private AdvertisementInService advertisementInService;
	
	/**
	 * 获得首页特权美食分类列表
	 * @Author 于泓磊
	 * @date   2017年10月31日
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/sfood")
	@ResponseBody
	public Object sFood(){
		logBefore(logger, "获得首页中美食分类列表接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("SORTFOOD", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("sDistance", pd)){	//检查参数
					//获得某家商店的综合评价
					List<PageData> list = sortinService.getSortFoodList(pd);
					for (PageData p : list) {
						p.put("HONOURUSER_ID", pd.get("HONOURUSER_ID"));
					}
					
					for (PageData data : list) {
						Map<String, String> m= (Map<String, String>) getDistance(data);
						data.put("distance",  m.get("distance"));
						//将地址修改为标准字符串
						data.put("SHOPADDRESS", data.get("SHOPADDRESS").toString().replace(",", ""));
					}
					//添加广告
					pd.put("RELATED_ID", "0");
					List<PageData> ad = advertisementInService.getAdByPosition(pd);
					map.put("ad", ad);
					map.put("pd", list);
				//返回01为添加成功并返回
				result =  "01";
				}else {
					result = "03";
				}
			}	
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 美食店铺添加用户评价接口
	 * @Author 于泓磊
	 * @date   2017年11月9日
	 * @return
	 */
	@RequestMapping(value="/sfoodaddeva")
	@ResponseBody
	public Object sFoodAddEva(){
		logBefore(logger, "美食店铺添加用户评价接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("SFOODADDEVA", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("sFoodAddEva", pd)){	//检查参数
				pd.put("FOODE_ID", this.getSnowId());
				pd.put("EVALUATEDATE", DateUtil.getDay());
				pd.put("EVALUATECOINT",Double.parseDouble((String) pd.get("EVALUATECOINT")));
				//用户是否匿名评价判断
				if (pd.get("ISSHOW").equals("1")) {
					pd.put("NICKNAME", "******");
				}else{
					pd.put("NICKNAME", sortinService.getUserNickName(pd).get("NICKNAME"));
				}
				sortinService.sFoodEvaAdd(pd);
				//每当店铺有新评价，则更新评价的分数和评价数量
				double d = sortinService.sFoodEvaMean(pd);
				Integer i = sortinService.sFoodEvaCount(pd);
				pd.put("SHOPEVALUATE", d);
				pd.put("SHOPEVACOUNT", i);
				sortinService.sFoodUpdEva(pd);
				//返回01为添加成功并返回
				result =  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	
	/**
	 * 获得某家店铺的综合评价
	 * @Author 于泓磊
	 * @date   2017年11月9日
	 * @return
	 */
	@RequestMapping(value="/sfoodmeaneva")
	@ResponseBody
	public Object sFoodMeanEva(){
		logBefore(logger, "美食店铺综合评价分数接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("SFOODMEANEVA", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("sFoodMeanEva", pd)){	//检查参数
					//获得某家商店的综合评价
					double d = sortinService.sFoodEvaMean(pd);
					map.put("pd", d);
				//返回01为添加成功并返回
				result =  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 获得某家店铺的评价数量
	 * @Author 于泓磊
	 * @date   2017年11月9日
	 * @return
	 */
	@RequestMapping(value="/sfoodcounteva")
	@ResponseBody
	public Object sFoodCountEva(){
		logBefore(logger, "某家店铺的评价数量接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("SFOODCOUNTEVA", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("sFoodMeanEva", pd)){	//检查参数
					//获得某家商店的综合评价
					Integer i = sortinService.sFoodEvaCount(pd);
					map.put("pd", i);
				//返回01为添加成功并返回
				result =  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 获得某家店铺的具体服务接口
	 * @Author 于泓磊
	 * @date   2017年11月10日
	 * @return
	 */
	@RequestMapping(value="/sfoodserv")
	@ResponseBody
	public Object sFoodServ(){
		logBefore(logger, "获得某家店铺的具体服务接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("SFOODSERV", pd.getString("FKEY"))){	//检验请求key值是否合法
					List<PageData> list = sortinService.sFoodServ(pd);
					if (list.size()!=0) {
						map.put("pd", list);
					}
				//返回01为添加成功并返回,02为此商铺暂无具体服务
				result = (0 == list.size()) ?  "02" :  "01";
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 美食详情综合接口
	 * @Author 于泓磊
	 * @date   2017年11月22日
	 * @return
	 */
	@RequestMapping(value="/foodsyn")
	@ResponseBody
	public Object FOODSyn(){
		logBefore(logger, "美食详情综合接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("SFOODSYN", pd.getString("FKEY"))){	//检验请求key值是否合法
				pd=sortinService.foodSyn(pd);
				 //调用工具类将数据库属性变成数组传到前台
				ToolsUtil.putImgstoArray(pd, "SHOPDETAILSIMGS");
				pd.remove("count(DISTINCT SORTFOOD_ID)");
				//将地址修改为标准字符串
				pd.put("SHOPADDRESS", pd.get("SHOPADDRESS").toString().replace(",", ""));
				map.put("pd", pd);
				//返回01为修改成功并返回
				result =  "01";
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 *	根据经纬度计算距离
	 * @param args
	 * @throws Exception
	 */
	public Object getDistance(PageData pd){
		Map<String,String> map = new HashMap<String,String>();
		String errInfo = "success",distance="";
		try {
			PageData p = sortinService.foodDistance(pd);
			distance  = MapDistance.getDistance(p.getString("SHOPLONGITUDE"),p.getString("SHOPLATITUDE"),p.getString("USERLONGITUDE"),p.getString("USERLATITUDE"));
		} catch (Exception e) {
			errInfo = "error";
		}
		map.put("result", errInfo);				//返回结果
		map.put("distance", distance);			//距离
		return AppUtil.returnObject(new PageData(), map);
	}
	

	/**
	 * 某美食店铺评价列表接口
	 * @Author 于泓磊
	 * @date   2017年11月25日
	 * @return
	 */
	@RequestMapping(value="/foodevalist")
	@ResponseBody
	public Object foodEvalist(){
		logBefore(logger, "某美食店铺评价列表接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("FOODEVA", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("sFoodMeanEva", pd)){	//检查参数
				List<PageData> list = sortinService.foodEvaList(pd);
				if (list.size()!=0) {
					map.put("pd", list);
				}
				//返回01为修改成功并返回
				result = (0 == list.size()) ?  "02" :  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 随机产生美食店铺列表
	 * @Author zhaozhenhua
	 * @date   2017年11月29日
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/sfoodlistrand")
	@ResponseBody
	public Object sFoodListRand(){
		logBefore(logger, "随机产生美食店铺列表");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("SORTFOODRAND", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("sDistance", pd)){	//检查参数
					//随机产生美食店铺列表
					List<PageData> list = sortinService.getFoodListByRand(pd);
					for (PageData p : list) {
						p.put("HONOURUSER_ID", pd.get("HONOURUSER_ID"));
					}
					for (PageData data : list) {
						Map<String, String> m= (Map<String, String>) getDistance(data);
						data.put("distance",  m.get("distance"));
						//将地址修改为标准字符串
						data.put("SHOPADDRESS", data.get("SHOPADDRESS").toString().replace(",", ""));
					}
					map.put("pd", list);
				//返回01为添加成功并返回
				result =  "01";
				}else {
					result = "03";
				}
			}	
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	
	/**
	 * 根据美食评价分数，价格，距离升序或者降序排序 
	 * @Author zhaozhenhua
	 * @date   2017年11月30日
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/sfoodlistsequence")
	@ResponseBody
	public Object sFoodListSequence(){
		logBefore(logger, "根据美食评价分数，价格，距离升序或者降序排序 ");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("SORTFOODSEQUENCE", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("sSequence", pd)){	//检查参数
					List<PageData> list = sortinService.getFoodListBySequence(pd);
					for (PageData p : list) {
						p.put("HONOURUSER_ID", pd.get("HONOURUSER_ID"));
					}
					for (PageData data : list) {
						Map<String, String> m= (Map<String, String>) getDistance(data);
						data.put("distance",  m.get("distance"));
						//将地址修改为标准字符串
						data.put("SHOPADDRESS", data.get("SHOPADDRESS").toString().replace(",", ""));
					}
					 if(pd.get("DISTANCE")==null&&pd.get("DISTANCE")==""){
	                    	//按距离对美食排序
	    					Collections.sort(list, new Comparator<PageData>(){
	    						@Override
	    						public int compare(PageData o1, PageData o2) {
	    							String dis1=(String) o1.get("distance");
	    							String dis2=(String) o2.get("distance");
	    							int intDis1 = Double.valueOf(dis1).intValue();
	    							int intDis2 = Double.valueOf(dis2).intValue();
	    							// 按照距离进行升序排列  
	    							if(intDis1>intDis2){
	    								return 1;
	    							}
	    							if(intDis1==intDis2){
	    								return 0;
	    							}
	    							return -1;
	    						}
	    					});
						}
					map.put("pd", list);
				//返回01为添加成功并返回
				result =  "01";
				}else {
					result = "03";
				}
			}	
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 获得美食套餐页列表
	 * @Author zhaozhenhua
	 * @date   2017年12月04日
	 * @return
	 */
	@RequestMapping(value="/fooddetaillist")
	@ResponseBody
	public Object personal(){
		logBefore(logger, "获得美食套餐页列表");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("FOODDETAIL", pd.getString("FKEY"))){	//检验请求key值是否合法
				List<PageData> list = sortinService.getFoodDetlist(pd);
					if (list.size()!=0) {
						map.put("pd", list);
					}
				//返回01为添加成功并返回,02为此商铺暂无具体服务
				result = (0 == list.size()) ?  "02" :  "01";
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 获得用户名下所有美食订单列表	(待付款，待使用，待评价)
	 * @Author zhaozhenhua
	 * @date   2017年12月04日
	 * @return
	 */
	@RequestMapping(value="/foodorderalllist")
	@ResponseBody
	public Object getAllFoodOrderList(){
		logBefore(logger, "获得用户名下所有美食订单列表接口(待付款，待使用，待评价)");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("ALLFOODORDER", pd.getString("FKEY"))){	//检验请求key值是否合法
				List<PageData> list = sortinService.getAllFoodOrderList(pd);
				if (list.size()!=0) {
					map.put("pd", list);
				}
				result = (0 == list.size()) ?  "02" :  "01";
			}else{
				result = "05";
			}
			
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	
	/**
	 * 生成美食订单接口（未产生交易）
	 * @Author zhaozhenhua
	 * @date   2017年12月04日
	 * @return
	 */
	@RequestMapping(value="/shipfoodorder")
	@ResponseBody
	public Object shipFOODOrder(){
		logBefore(logger, "生成美食订单接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		PageData po = new PageData();
		po = this.getPageData();
		try{
			if(Tools.checkKey("SHIPFOODORDER", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("shipFoodOrder", pd)){	//检查参数
					String FOODORDER_ID = this.getSnowId();
					pd.put("FOODORDER_ID", FOODORDER_ID);
					//调用工具类生成美食订单号
					String getnum = ToolsUtil.GetHotelOrderID(pd.getString("HONOURUSER_ID"));
					pd.put("ORDERNUMBER",getnum);
					pd.put("ORDERTIME", ToolsUtil.getStringDate());
					//将美食订单状态改为待付款
					pd.put("ORDERSTATUS", "0040001");
					//添加相对应的美食订单
					sortinService.addFoodOrder(pd);
					//添加相对应的用户订单中间信息
					po.put("USERORDER_ID", this.getSnowId());
					po.put("ORDERTYPE", "2");   //1代表美食2代表美食3代表ktv
					po.put("HONOURUSER_ID", pd.getString("HONOURUSER_ID"));
					po.put("SORTTYPE_ID", FOODORDER_ID);
					sortinService.addUserOrder(po);
					//返回01为创建成功并返回
					map.put("ORDERNUMBER", getnum);
					result =  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	
	/**
	 * 生成美食酒店酒吧KTV订单接口
	  * @Description
	  * @Author zhaozhenhua
	  * @date   2018年5月14日
	  * @param pd
	  * @return
	  * @throws Exception
	 */
	@RequestMapping(value="/addloworder")
	@ResponseBody
	public Object shipLowOrder(){
		logBefore(logger, "生成美食酒店酒吧KTV订单接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		PageData po = new PageData();
		po = this.getPageData();
		try{
			if(Tools.checkKey("ADDLOWORDER", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("shipFoodOrder", pd)){	//检查参数
					String ORDERTYPE = pd.getString("ORDERTYPE");//1代表美食2代表酒店3代表ktv4代表酒吧
					String ORDER_ID = this.getSnowId();
					//调用工具类生成美食订单号
					String getnum = ToolsUtil.GetHotelOrderID(pd.getString("HONOURUSER_ID"));
					pd.put("ORDERNUMBER", getnum);
					pd.put("ORDERTIME", ToolsUtil.getStringDate());
					//将美食订单状态改为待付款
					pd.put("ORDERSTATUS", "0040001");
					String PAYTYPE = pd.getString("PAYTYPE");
					String orderStr = "";//支付宝或微信所需信息
					switch (ORDERTYPE) {
					case "1":
						pd.put("FOODORDER_ID", ORDER_ID);
						pd.put("FOODDETAIL_ID", pd.get("DETAIL_ID"));
						pd.put("ORDERCHECKDATE", pd.get("ORDERROOMBEGIN"));
						pd.put("ORDERLEAVEDATE", pd.get("ORDERROOMEND"));
						sortinService.addFoodOrder(pd);
						//调用支付宝或微信接口生成支付信息
						if(PAYTYPE.equals("支付宝")){
							orderStr = AliPayUtil.aliPay(pd);
							map.put("PAYTYPE", "支付宝");
							map.put("orderStr", orderStr);
						}if(PAYTYPE.equals("微信")){
							pd.put("spbillCreateIp", NetworkUtil.getIPAddress(getRequest()));
							SortedMap<String, Object> weixinPrePay = WXPayUtil.weixinPrePay(pd);
							map.put("orderStr", weixinPrePay);
							map.put("PAYTYPE", "微信");
						}
						break;
					case "2":
						pd.put("HOTELORDER_ID", ORDER_ID);
						pd.put("HOTELDETAIL_ID", pd.get("DETAIL_ID"));
						pd.put("ORDERCHECKDATE", pd.get("ORDERROOMBEGIN"));
						pd.put("ORDERLEAVEDATE", pd.get("ORDERROOMEND"));
						sortinService.addHotelOrder(pd);
						//调用支付宝或微信接口生成支付信息
						if(PAYTYPE.equals("支付宝")){
							orderStr = AliPayUtil.aliPay(pd);
							map.put("PAYTYPE", "支付宝");
							map.put("orderStr", orderStr);
						}if(PAYTYPE.equals("微信")){
							pd.put("spbillCreateIp", NetworkUtil.getIPAddress(getRequest()));
							SortedMap<String, Object> weixinPrePay = WXPayUtil.weixinPrePay(pd);
							map.put("orderStr", weixinPrePay);
							map.put("PAYTYPE", "微信");
						}
						break;
					case "3":
						pd.put("KTVORDER_ID", ORDER_ID);
						pd.put("KTVDETAIL_ID", pd.get("DETAIL_ID"));
						sortinService.addKTVOrder(pd);
						//调用支付宝或微信接口生成支付信息
						if(PAYTYPE.equals("支付宝")){
							orderStr = AliPayUtil.aliPay(pd);
							map.put("PAYTYPE", "支付宝");
							map.put("orderStr", orderStr);
						}if(PAYTYPE.equals("微信")){
							pd.put("spbillCreateIp", NetworkUtil.getIPAddress(getRequest()));
							SortedMap<String, Object> weixinPrePay = WXPayUtil.weixinPrePay(pd);
							map.put("orderStr", weixinPrePay);
							map.put("PAYTYPE", "微信");
						}
						break;
					case "4":
						pd.put("BARORDER_ID", ORDER_ID);
						pd.put("BARDETAIL_ID", pd.get("DETAIL_ID"));
						sortinService.addBarOrder(pd);
						//调用支付宝或微信接口生成支付信息
						if(PAYTYPE.equals("支付宝")){
							orderStr = AliPayUtil.aliPay(pd);
							map.put("PAYTYPE", "支付宝");
							map.put("orderStr", orderStr);
						}if(PAYTYPE.equals("微信")){
							pd.put("spbillCreateIp", NetworkUtil.getIPAddress(getRequest()));
							SortedMap<String, Object> weixinPrePay = WXPayUtil.weixinPrePay(pd);
							map.put("orderStr", weixinPrePay);
							map.put("PAYTYPE", "微信");
						}
						break;
					default:
						break;
					}
					
					//添加相对应的用户订单中间信息
					po.put("USERORDER_ID", this.getSnowId());
					po.put("ORDERTYPE", ORDERTYPE);   //1代表美食2代表美食3代表ktv
					po.put("HONOURUSER_ID", pd.getString("HONOURUSER_ID"));
					po.put("SORTTYPE_ID", ORDER_ID);
					sortinService.addUserOrder(po);
					//返回01为创建成功并返回
					map.put("ORDERNUMBER", getnum);
					result =  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 修改美食订单状态(改为支付成功)
	 * @Author zhaozhenhua
	 * @date   2017年12月04日
	 * @return
	 */
	@RequestMapping(value="/shiporderstaupd")
	@ResponseBody
	public Object shipFoodOrderStaUpd(){
		logBefore(logger, "修改美食订单状态接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("SHIPFOODORDERUPD", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("shipHotelOrderStaUpd", pd)){	//检查参数
				//对美食订单状态进行修改
				pd.put("ORDERPAYTIME", ToolsUtil.getStringDate());
				sortinService.updFoodOrderStatus(pd);
				//订单状态为0040003时,获取购物分
				if("0040003".equals(pd.getString("ORDERSTATUS"))){
					//获取参与分值
					Integer score = energyInService.getShareScore(pd);
					//获取原始分值
					PageData energyScore = userinService.getEnergyScore(pd);
					Integer SHOPSCORE=energyScore.getInterger("SHOPSCORE")+score;
					pd.put("SHOPSCORE", SHOPSCORE);
					userinService.updEnergyScore(pd);
				}
				//返回01为修改成功并返回
				result =  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 查询所有品牌或者类型
	 * @Author zhaozhenhua
	 * @date   2017年12月06日
	 * @return
	 */
	@RequestMapping(value="/brandstylelist")
	@ResponseBody
	public Object getBrandList(){
		logBefore(logger, "查询所有品牌或者类型");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		List<PageData> list=new ArrayList<>();
		try{
			if(Tools.checkKey("BRANDLIST", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("shipBrandStyleList", pd)){	//检查参数
					if(pd.get("TYPE").equals("0")){             //0代表查询品牌
					    list = sortinService.getBrandList(pd);  
					}if(pd.get("TYPE").equals("1")) {          //1代表查询类型
						list=sortinService.getStyleList(pd);
					}
					map.put("pd", list);
					result =  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 后台酒吧，KTV，美食，酒店添加品牌或分类
	  * @Description
	  * @Author zhaozhenhua
	  * @date   2018年3月7日
	  * @param pd
	  * @return
	  * @throws Exception
	 */
	@RequestMapping(value="/addbrandorcate")
	@ResponseBody
	public Object addBrandOrCate(){
		logBefore(logger, "后台酒吧，KTV，美食，酒店添加品牌或分类");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("ADDBRANDORCATE", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("sortBrandOrCate", pd)){	//检查参数
					pd.put("SORT_ID", this.getSnowId());
					sortinService.addBrandOrCate(pd);
					map.put("SORT_ID", pd.get("SORT_ID"));
					result =  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 后台酒吧，KTV，美食，酒店修改品牌或分类
	  * @Description
	  * @Author zhaozhenhua
	  * @date   2018年3月7日
	  * @param pd
	  * @return
	  * @throws Exception
	 */
	@RequestMapping(value="/updbrandorcate")
	@ResponseBody
	public Object updBrandOrCate(){
		logBefore(logger, "后台酒吧，KTV，美食，酒店修改品牌或分类");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("UPDBRANDORCATE", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("sortBrandOrCate", pd)){	//检查参数
					sortinService.updBrandOrCate(pd);
					result =  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 后台酒吧，KTV，美食，酒店根据id获取品牌或分类
	  * @Description
	  * @Author zhaozhenhua
	  * @date   2018年3月7日
	  * @param pd
	  * @return
	  * @throws Exception
	 */
	@RequestMapping(value="/getbrandorcatebyId")
	@ResponseBody
	public Object getBrandOrCateById(){
		logBefore(logger, "后台酒吧，KTV，美食，酒店根据id获取品牌或分类");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("GETBRANDORCATEBYID", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("getBrandOrCateById", pd)){	//检查参数
					PageData p = sortinService.findById(pd);
					map.put("pd", p);
					result = (p==null)?"02": "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}

}
